<?php
class Employee_model extends CI_Model {
        
    public function __construct()
    {
        parent::__construct();
        $this->load->model('query');
        $this->config->load('iss_config');
    }
    
    public function get_employee(){
         
         $sql = "SELECT emp_id,name,birthday,email,emp_level,tax_num,dep_id,salary FROM ".$this->config->item('schema').".employee";
         return $this->query->select_query($sql);
    }
    public function get_employee_by_id($id){
         
         $sql = "SELECT emp_id,name,birthday,email,emp_level,tax_num,dep_id,salary FROM ".$this->config->item('schema').".employee where emp_id='".$id."'";
         return $this->query->select_query($sql);
    }
  
   public function update_employee($data ){
        $this->session->set_flashdata('type', 'update');
        $this->session->set_flashdata('table', 'Employee');
        $sql = "UPDATE ".$this->config->item('schema').".Employee
                    SET 
                         name='".$data['name']."'"
                         . ",birthday='".$data['birthday']."'"
                         . ",email='".$data['email']."'"
                         . ",emp_level='".$data['emp_level']."'"
                         . ",tax_num=".$data['tax_num'].""
                         . ",dep_id='".$data['dept_id']."'"


                         . ",salary=".$data['sal']."

                     WHERE emp_id='".$data['emp_id']."'";
       
        return $this->query->update_query($sql);
   }

    public function  store_employee($data){
         $this->session->set_flashdata('type', 'add');
         $this->session->set_flashdata('table', 'Employee');

          $sql = "INSERT INTO ".$this->config->item('schema').".EMPLOYEE(emp_id,name,birthday,email,emp_level,tax_num,dep_id,salary) "


                . "VALUES ('".$data['emp_id']."','".$data['name']."','".$data['birthday']."','".$data['email']."','".$data['emp_level']."'"
                . ",".$data['tax_num'].",'".$data['dept_id']."',".$data['sal'].")" ;            

         return $this->query->update_query($sql);
    }

    public function delete_employee($id){
         $this->session->set_flashdata('type', 'del');
         $this->session->set_flashdata('table', 'Employee');
        $sql = "DELETE FROM ".$this->config->item('schema').".EMPLOYEE WHERE emp_id='".$id."'";
        return $this->query->update_query($sql);
    }
    
    public function update_af_in_employee($data){
         $this->session->set_flashdata('type', 'update');
         $this->session->set_flashdata('table', 'Employee');
        $sql = "UPDATE ".$this->config->item('schema').".Employee
                    SET 
                      ".$data['af_emp_field']."=".$data['af_value']." "
                       . "WHERE emp_id='".$data['af_emp_id']."'";
        return $this->query->update_query($sql);
    }

}